package com.example.buyticketlishi.view.ac;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.baselibrary.Base.BaseActivity;
import com.example.baselibrary.Utils.Customer;
import com.example.baselibrary.Utils.SPUtils;
import com.example.baselibrary.Utils.StringUtil;
import com.example.baselibrary.Utils.ToastUtil;
import com.example.buyticketlishi.R;

public class SettingIPActivity extends BaseActivity {

    private EditText IpInput;
    private Button btSave;
    private Button btBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected int getView() {
        return R.layout.activity_setting_ip;
    }

    @Override
    public void init() {
        IpInput = (EditText) findViewById(R.id.et_ip_input);
        btSave = (Button) findViewById(R.id.bt_save);
        btBack = (Button) findViewById(R.id.bt_back);
        IpInput.setText((String) SPUtils.get(SettingIPActivity.this,Customer.LiSHI_INPUT_URL,""));

        doThing();
    }

    private void doThing() {
        btSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //判断输入的是否是url
                String input = IpInput.getText().toString().trim();
                if (StringUtil.isURL(input)) {
                    // 输入正确的地址，对地址进行保存
                    SPUtils.put(SettingIPActivity.this,  Customer.LiSHI_INPUT_URL, input);
                    Base_URL = input;
                    ToastUtil.showToast("地址保存成功");
                } else {
                    ToastUtil.showToast("请输入正确的地址");
                }
            }
        });

        btBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }
}
